package com.hcrazy.manchester.app.jdbc;

import java.util.List;

import com.hcrazy.manchester.app.pojo.RadioTag;

public class RadioTagDAO extends BaseDAO<RadioTag>{

	public void addRadioTag(RadioTag tag) throws Exception{
		StringBuffer sb = new StringBuffer();
		sb.append("insert into him_radio_tag(");
		sb.append("tagName,parentId,tagType,moduleType,tagOrder");
		sb.append(") values (");
		sb.append(":tagName,:parentId,:tagType,:moduleType,:tagOrder");
		sb.append(")");
		
		update(sb.toString(), tag);
	}
	
	public void updateRadioTag(RadioTag tag) throws Exception{
		StringBuffer sb = new StringBuffer();
		sb.append("update him_radio_tag set ");
		sb.append(" tagName=:tagName,tagOrder=:tagOrder,parentId=:parentId,moduleType=:moduleType,tagType=:tagType");
		sb.append(" where tagId = :tagId");
		
		update(sb.toString(), tag);
	}
	
	public List<RadioTag> listAllSorts(int moduleType) throws Exception{
		String sql = "select * from him_radio_tag where moduleType = ? order by tagOrder";
		return getList(sql, RadioTag.class,moduleType);
	}
	
	public RadioTag getById(int tagId) throws Exception{
		String sql = "select * from him_radio_tag where tagId = ?";
		return this.getJavaBean(sql, RadioTag.class, tagId);
	}
	
	public List<RadioTag> getByParentId(int parentId) throws Exception{
		String sql = "select * from him_radio_tag where parentId = ?";
		return getList(sql, RadioTag.class,parentId);
	}
	
	public void delRadioTag(int tagId) throws Exception{
		String sql = "delete from him_radio_tag where tagId = ?";
		this.commonUpdate(sql, tagId);
	}
	
	public void delRadioTagByParentId(int parentId) throws Exception{
		String sql = "delete from him_radio_tag where parentId = ?";
		this.commonUpdate(sql, parentId);
	}
	
	public boolean hasChildren(int parentId) throws Exception{
		String sql = "select count(*) from him_radio_tag where parentId = ?";
		int count = getCount(sql, parentId);

		return count > 0;
	}
}
